package com.zuilapsa.jmc.actions;

import java.util.Enumeration;

import com.zuilapsa.jmc.*;
import com.zuilapsa.jmc.model.*;
import com.zuilapsa.jmc.userInterfaces.*;

public class ActionShow extends ActionNull {

	public void execute(UserInterfaceSession interfaceSession, String[] args) {
		// TODO consider updating to level interface (get rid of xml)
		Level level = interfaceSession.getLevel();
		// Element cfg = interfaceSession.getConfigElement();

		interfaceSession.printMessageInfo("levels:");
		for (Enumeration en = level.getLevelGlobs().keys(); en
				.hasMoreElements();) {
			interfaceSession.printMessageInfo(" "+(String) en.nextElement());
		}
		try {
			for (Enumeration en = level.getTokens().keys(); en
					.hasMoreElements();) {
				Token t = level.getToken((String) en.nextElement());
				if (t.getDefinitionWrapper().isLevel())
					interfaceSession.printMessageInfo(" " + t.getName());
			}
		} catch (JmcException e) {
			interfaceSession.printMessageError("Unable to read levels");
		}

		
		interfaceSession.printMessageInfo("properties:");
		for (Enumeration en = level.getPropertyGlobs().keys(); en
				.hasMoreElements();) {
			interfaceSession.printMessageInfo(" "+(String) en.nextElement());
		}

		for (Enumeration en = level.getProperties().keys(); en
				.hasMoreElements();) {
			Property p = level.getProperty((String) en.nextElement());
			interfaceSession.printMessageInfo(" " + p.getName() + " = "
					+ p.getValue());
		}
	}

	public String getHelpString() {
		return "Displays all properties and sub levels.";
	}
}
